﻿<phone:PhoneApplicationPage 
    Name="Page"
    x:Class="Organizer.Views.NotesPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"    
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait" Orientation="Portrait"
    mc:Ignorable="d" d:DesignHeight="768" d:DesignWidth="480"
    xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
    xmlns:Code="clr-namespace:BindableAppBarSample.Code;assembly=BindableAppBarSample"
    xmlns:Views="clr-namespace:Organizer.Views"
    xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
    xmlns:cmd="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras.WP71"
    xmlns:local="clr-namespace:Organizer.External.Helpers" shell:SystemTray.IsVisible="True">

    <toolkit:TransitionService.NavigationInTransition>
        <toolkit:NavigationInTransition>
            <toolkit:NavigationInTransition.Backward>
                <toolkit:TurnstileTransition Mode="BackwardIn"/>
            </toolkit:NavigationInTransition.Backward>
            <toolkit:NavigationInTransition.Forward>
                <toolkit:TurnstileTransition Mode="ForwardIn"/>
            </toolkit:NavigationInTransition.Forward>
        </toolkit:NavigationInTransition>
    </toolkit:TransitionService.NavigationInTransition>
    <toolkit:TransitionService.NavigationOutTransition>
        <toolkit:NavigationOutTransition>
            <toolkit:NavigationOutTransition.Backward>
                <toolkit:TurnstileTransition Mode="BackwardOut"/>
            </toolkit:NavigationOutTransition.Backward>
            <toolkit:NavigationOutTransition.Forward>
                <toolkit:TurnstileTransition Mode="ForwardOut"/>
            </toolkit:NavigationOutTransition.Forward>
        </toolkit:NavigationOutTransition>
    </toolkit:TransitionService.NavigationOutTransition>

    <phone:PhoneApplicationPage.DataContext>
        <Views:NoteViewModel />
    </phone:PhoneApplicationPage.DataContext>

    <phone:PhoneApplicationPage.Resources>
        <DataTemplate x:Key="CustomItemTemplate">
            <StackPanel x:Name="sp">
                <StackPanel Orientation="Horizontal">
                    <CheckBox HorizontalAlignment="Left" IsChecked="{Binding IsSelectedMultiSelect, Mode=TwoWay}" 
                              Visibility="{Binding ElementName=Page, Path=DataContext.Status, Converter={StaticResource manageSelectionStateToVisibilityConverter}}" />
                    <StackPanel>
                        <toolkit:ContextMenuService.ContextMenu>
                            <toolkit:ContextMenu>
                                <toolkit:MenuItem x:Name="miEdit" Header="{Binding Path=LocalizedResources.ContextMenuEdit, Source={StaticResource LocalizedStrings}}" />
                                <toolkit:MenuItem x:Name="miRemove" Header="{Binding Path=LocalizedResources.ContextMenuRemove, Source={StaticResource LocalizedStrings}}" >
                                    <i:Interaction.Triggers>
                                        <i:EventTrigger EventName="Tap">
                                            <cmd:EventToCommand Command="{Binding DeleteCommand}" />
                                            <cmd:EventToCommand Command="{Binding ElementName=Page, Path=DataContext.RefreshCommand}" />
                                        </i:EventTrigger>
                                    </i:Interaction.Triggers>
                                </toolkit:MenuItem>
                            </toolkit:ContextMenu>
                        </toolkit:ContextMenuService.ContextMenu>
                        <TextBlock Text="{Binding Description}" TextWrapping="NoWrap" Style="{StaticResource PhoneTextLargeStyle}"/>
                        <TextBlock Text="{Binding TimeCreate}" TextWrapping="Wrap" Style="{StaticResource PhoneTextSmallStyle}"/>
                        <i:Interaction.Triggers>
                            <i:EventTrigger EventName="Tap">
                                <cmd:EventToCommand Command="{Binding ElementName=Page, Path=DataContext.EditCommand}" CommandParameter="{Binding}" />
                            </i:EventTrigger>
                        </i:Interaction.Triggers>
                    </StackPanel>
                </StackPanel>
            </StackPanel>
        </DataTemplate>
    </phone:PhoneApplicationPage.Resources>

    <Grid x:Name="LayoutRoot" Background="Transparent">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
            <TextBlock x:Name="ApplicationTitle" Text="{Binding Path=LocalizedResources.AppName, Source={StaticResource LocalizedStrings}}" Style="{StaticResource PhoneTextNormalStyle}"/>
            <TextBlock x:Name="PageTitle" Text="{Binding Path=LocalizedResources.NotesPage_Title, Source={StaticResource LocalizedStrings}}" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
        </StackPanel>

        <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
            <ItemsControl x:Name="multiSelectList"  ItemTemplate="{StaticResource CustomItemTemplate}" ItemsSource="{Binding Notes}" >
            </ItemsControl>
            <StackPanel Height="595"
                        Opacity="1" 
                        Background="{StaticResource PhoneBackgroundBrush}"                          
                        HorizontalAlignment="Left" 
                        Name="stackPanel1" 
                        VerticalAlignment="Top" Width="445" 
                        Visibility="{Binding Path=Status, Converter={StaticResource editStateToVisibilityConverter}}">
                <TextBlock x:Name="tbNoteDesc" 
                           Text="{Binding Path=LocalizedResources.NotesPage_Description, Source={StaticResource LocalizedStrings}}" 
                           Margin="12,0,0,0"
                           Style="{StaticResource TextLighter}"/>
                
                <TextBox x:Name="tbDescription"
                    Width="445" Height="Auto" MinHeight="400" 
                    Text="{Binding EditedNote.Description,Mode=TwoWay}" 
                    local:BindingHelper.UpdateSourceOnChange="True"
                    HorizontalAlignment="Left" d:LayoutOverrides="Height" >
                    <TextBox.InputScope>
                        <InputScope>
                            <InputScopeName NameValue="Text" />
                        </InputScope>
                    </TextBox.InputScope>
                </TextBox>
                <TextBlock x:Name="tbNoteTimeCreate" 
                           Text="{Binding EditedNote.TimeCreate}" 
                           TextWrapping="Wrap" 
                           Style="{StaticResource PhoneTextSmallStyle}"/>

            </StackPanel>
        </Grid>
    </Grid>

    <Code:BindableApplicationBar.BindableApplicationBar>
        <Code:BindableApplicationBar>
            <Code:BindableApplicationBar.ButtonDelegates>
                <Code:ApplicationBarIconButtonDelegate Command="{Binding AddCommand}" IconUri="/Images\Icons/appbar.add.rest.png" Text="add" Click="ApplicationBarIconButtonDelegate_Click"
                                                       IsVisible="{Binding Path=Status,Converter={StaticResource normalStateToVisibilityConverter}}" />
                <Code:ApplicationBarIconButtonDelegate Command="{Binding ManageCommand}" IconUri="/Images\Icons/appbar.manage.rest.png" Text="manage" 
                                                       IsVisible="{Binding Path=Status,Converter={StaticResource normalStateToVisibilityConverter}}" />
                <Code:ApplicationBarIconButtonDelegate Command="{Binding SaveCommand}" IconUri="/Images\Icons/appbar.save.rest.png" Text="save" 
                                                       IsVisible="{Binding Path=Status,Converter={StaticResource editStateToVisibilityConverter}}" />
                <Code:ApplicationBarIconButtonDelegate Command="{Binding CancelCommand}" IconUri="/Images\Icons/appbar.cancel.rest.png" Text="cancel" 
                                                       IsVisible="{Binding Path=Status,Converter={StaticResource editStateToVisibilityConverter}}" />
                <Code:ApplicationBarIconButtonDelegate Command="{Binding DeleteNotesCommand}" IconUri="/Images\Icons/appbar.delete.rest.png" Text="delete"
                                                       IsVisible="{Binding Path=Status,Converter={StaticResource manageSelectionStateToVisibilityConverter}}"/>
            </Code:BindableApplicationBar.ButtonDelegates>
            <Code:BindableApplicationBar.MenuItemDelegates>
                <!--<Code:ApplicationBarMenuItemDelegate  Text="select all" Command="{Binding SelectAll}" />
                <Code:ApplicationBarMenuItemDelegate  Text="unselect all" Command="{Binding UnselectAll}" />-->
            </Code:BindableApplicationBar.MenuItemDelegates>
        </Code:BindableApplicationBar>
    </Code:BindableApplicationBar.BindableApplicationBar>

</phone:PhoneApplicationPage>
